//
//  MYGAcademicSchuledDetailHeaderView.swift
//  MYDoctor
//
//  Created by 小火科技 on 2024/5/30.
//

import UIKit

class MYGAcademicSchuledDetailHeaderView: UIView {
    
    func getHeaderData(model:MYGAcademicForeignModel){
        
        titleLB.text = model.roomCn
//        let arr = model.roomEndTime.components(separatedBy: " ")
//        countTitle.text = "时间: \(model.roomStartTime)-\(arr.last ?? "")"
        countTitle.text = "时间: \(model.sessionTime)"
        titleLB.text = model.sessionCn
        
    }
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = .rgba(69, 131, 250, 0.06)
       
        addSubview(topImageView)
        addSubview(popBackBtn)
        addSubview(titleLabel)
        topImageView.addSubview(titleLB)
        topImageView.addSubview(countTitle)
        topImageView.addSubview(countLB)
        
        topImageView.snp.makeConstraints { make in
            make.left.right.top.equalToSuperview()
            make.bottom.equalToSuperview().inset(49)
        }
        
        titleLabel.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(statusBarHeight + 12)
        }
        popBackBtn.snp.makeConstraints { make in
            make.width.height.equalTo(44)
            make.left.equalTo(18)
            make.centerY.equalTo(titleLabel)
        }
       
        titleLB.snp.makeConstraints { make in
            make.left.equalTo(20)
            make.right.equalToSuperview()
            make.top.equalTo(95)
            make.height.equalTo(37)
        }
        
        countTitle.snp.makeConstraints { make in
            make.left.equalTo(titleLB)
            make.top.equalTo(titleLB.snp.bottom).offset(5)
            make.height.equalTo(20)
        }
        
        countLB.snp.makeConstraints { make in
            make.left.equalTo(titleLB)
            make.top.equalTo(countTitle.snp.bottom).offset(5)
            make.height.equalTo(20)
        }
        
        let arra = ["时间","讲题","任务","姓名"]
        for (index, item) in arra.enumerated() {
            let control = UILabel()
            control.text = item
            control.textAlignment = index == 1 ? .left : .center
            control.textColor = .rgba(48, 78, 236, 1)
            control.font = .regular(13)
            addSubview(control)
            
            var w:CGFloat = 0
            var left:CGFloat = 0
            if index == 0 {
                w = 100
                left = 0
//                control.backgroundColor = .red
            }else if index == 1 {
                w = screenWidth - 240
                left = 100
//                control.backgroundColor = .orange
            }else {
                w = 70
                left = index == 2 ? screenWidth - 140 : screenWidth - 70
//                control.backgroundColor = .yellow
            }
            
            control.snp.makeConstraints { make in
                make.left.equalToSuperview().offset(left)
                make.width.equalTo(w)
                make.top.equalTo(topImageView.snp.bottom).offset(15)
            }
            
        }
        
    }
    
    @objc func backAction() {
        UIViewController.currentViewController?.navigationController?.popViewController(animated: true)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private var titleLabel:UILabel = {
        let control = UILabel()
        control.text = "日程详情"
        control.textColor = .rgba(255, 255, 255, 1)
        control.font = .medium(18)
        return control
    }()
    
    lazy var popBackBtn: UIButton = {
        let control = UIButton(type: .custom)
        control.frame = CGRect(x: 0, y: 0, width: 40, height: 40)
        control.tintColor = .white
        control.setImage(UIImage(named: "Chat/back"), for: .normal)
        control.addTarget(self, action: #selector(backAction), for: .touchUpInside)
        return control
    }()

    private lazy var topImageView:UIImageView = {
        let imageView = UIImageView()
        imageView.image = UIImage(named: "Nav bar")
        return imageView
    }()
    
    private var titleLB:UILabel = {
        let control = UILabel()
        control.text = "负责病例分析1:TAMVR"
        control.textColor = .rgba(255, 255, 255, 1)
        control.font = .medium(26)
        return control
    }()
    
    private  var countTitle:UILabel = {
        let control = UILabel()
        control.text = "时间：2023-01-06 08:00-12:00"
        control.font = .medium(14)
        control.textColor = .rgba(255, 255, 255, 1)
        return control
    }()
    
    private var countLB:UILabel = {
        let control = UILabel()
        control.text = "会场：手术直播专场"
        control.font = .medium(14)
        control.textColor = .rgba(255, 255, 255, 1)
        return control
    }()
    
}
